package com.vincent.template.commons.base;

/**
 * @Author Vincent Wang
 * @Date 2020/10/16 15:55
 */
public class BaseResultDto<T> {

    public static final int SUCCESS_CODE = 0;
    public static final int ERROR_CODE = 1;
    public static final String SUCCESS_MSG = "success";

    /**
     * 返回码
     */
    private int code;

    /**
     * 结果信息
     */
    private String message;

    /**
     * 业务数据
     */
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public BaseResultDto(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> BaseResultDto<T> success(T data) {
        return new BaseResultDto<>(SUCCESS_CODE, SUCCESS_MSG, data);
    }

    public static <T> BaseResultDto<T> fail(String message) {
        return new BaseResultDto<>(ERROR_CODE, message, null);
    }

}
